/*
 * @lc app=leetcode.cn id=1582 lang=javascript
 *
 * [1582] 二进制矩阵中的特殊位置
 */

// @lc code=start
/**
 * @param {number[][]} mat
 * @return {number}
 */
var numSpecial = function (mat) {
  const rows = Array(mat.length).fill(0), cols = Array(mat[0].length).fill(0);
  for (let i = 0; i < mat.length; i++) {
    for (let j = 0; j < mat[0].length; j++) {
      rows[i] += mat[i][j];
      cols[j] += mat[i][j];
    }
  }
  let sum = 0;
  for (let i = 0; i < rows.length; i++) {
    if (rows[i] === 1) {
      if (cols[mat[i].indexOf(1)] === 1) {
        sum++;
      }
    }
  }
  return sum;
};
// @lc code=end


